<template>
  <div class="userSearch">
    <el-form :model="searchForm" ref="formRef" label-width="80px" >
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="用户名" prop="name">
            <el-input v-model="searchForm.name" placeholder="请输入查询的用户名" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="真实姓名" prop="realname">
            <el-input v-model="searchForm.realname" placeholder="请输入查询的真实姓名" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="电话号码" prop="cellphone">
            <el-input v-model="searchForm.cellphone" placeholder="请输入查询的电话号码" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="状态" prop="enable">
            <el-select  v-model="searchForm.enable" placeholder="选择状态" style="width: 100%;">
              <el-option label="启用" :value="1" />
              <el-option label="禁用" :value="0" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item  label="创建时间" prop="createAt">
            <el-date-picker 
              type="daterange"
              range-separator="-"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              v-model="searchForm.createAt"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <div class="btns">
      <el-button icon="Refresh" @click="handleResetClick">重置</el-button>
      <el-button icon="Search" type="primary" @click="handleQueryClick">查询</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import type { ElForm } from 'element-plus';
import { reactive, ref } from 'vue'

//定义事件
const emit = defineEmits(['queryClick', 'resetClick'])

const searchForm = reactive({
  name: '',
  realname: '',
  cellphone: '',
  enable: 1,
  createAt: ''
})

//查询重置
const formRef = ref<InstanceType<typeof ElForm>>()
const handleResetClick = ()=> {
  formRef.value?.resetFields()
  emit('resetClick', searchForm)
}

//查询
const handleQueryClick = () => {
  emit('queryClick', searchForm)
}
</script>

<style scoped lang="less">
.userSearch {
  background-color: #fff;
  border-radius: 10px;
  padding: 20px;

  .el-form-item {
    padding: 3px;
    margin-top: 0;
  }
  .btns {
    margin-right: 0px;
    text-align: right;
    padding: 0 50px 10px 0;
  }
}
</style>
